/**
 * @author gao
 * @date 2025/6/24 17:55
 */

public class Demo3 {
    public static boolean flag = true;

    public static void main(String[] args) throws InterruptedException {
        Thread t = new Thread(() -> {
            while (flag) {
                System.out.println("hello thread");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        });
        t.start();

        System.out.println("hello main");
        Thread.sleep(5000);
        flag = false;
        System.out.println("让t线程终止");
    }
}